--- src/libaccountsservice/act-user-manager.c.orig	2023-03-15 15:09:35 UTC
+++ src/libaccountsservice/act-user-manager.c
@@ -40,7 +40,8 @@
 #include <glib-object.h>
 #include <gio/gio.h>
 #include <gio/gunixinputstream.h>
-#include <systemd/sd-login.h>
+#include <libconsolekit.h>
+#include <sd-login.h>
 
 #include "act-user-manager.h"
 #include "act-user-private.h"
@@ -100,9 +101,6 @@ typedef struct
         char                   *id;
         char                   *session_id;
         guint                   load_idle_id;
-        sd_login_monitor       *session_monitor;
-        GInputStream           *session_monitor_stream;
-        guint                   session_monitor_source_id;
 } ActUserManagerSeat;
 
 typedef enum
@@ -165,6 +163,8 @@ typedef struct
 
         ActUserManagerSeat seat;
 
+        LibConsoleKit     *ck;
+
         GSList            *new_sessions;
         GSList            *new_users;                 /* (element-type ActUser) (owned) */
         GSList            *new_users_inhibiting_load; /* (element-type ActUser) (unowned) */
@@ -271,9 +271,9 @@ activate_systemd_session_id (ActUserManager *manager,
         }
 
         reply = g_dbus_connection_call_sync (connection,
-                                             "org.freedesktop.login1",
-                                             "/org/freedesktop/login1",
-                                             "org.freedesktop.login1.Manager",
+                                             "org.freedesktop.ConsoleKit",
+                                             "/org/freedesktop/ConsoleKit/Manager",
+                                             "org.freedesktop.ConsoleKit.Manager",
                                              "ActivateSessionOnSeat",
                                              g_variant_new ("(ss)",
                                                             seat_id,
@@ -318,9 +318,7 @@ session_is_on_our_seat (ActUserManager *manager,
         g_autofree gchar *session_seat = NULL;
 
         res = sd_session_get_seat (session_id, &session_seat);
-        if (res == -ENODATA) {
-                return FALSE;
-        } else if (res < 0) {
+        if (res < 0) {
                 g_debug ("failed to determine seat of session %s: %s",
                          session_id,
                          strerror (-res));
@@ -521,7 +519,7 @@ queue_load_seat_incrementally (ActUserManager *manager
 static gboolean
 _systemd_session_is_graphical (const char *session_id)
 {
-        const gchar * const graphical_session_types[] = { "wayland", "x11", "mir", NULL };
+        const gchar * const graphical_session_types[] = { "wayland", "x11", NULL };
         int saved_errno;
         g_autofree gchar *type = NULL;
 
@@ -637,9 +635,7 @@ get_seat_id_for_current_session (ActUserManager *manag
 
         res = sd_session_get_seat (priv->seat.session_id, &seat_id);
 
-        if (res == -ENODATA) {
-                seat_id = NULL;
-        } else if (res < 0) {
+        if (res < 0) {
                 g_warning ("Could not get current seat: %s",
                            strerror (-res));
                 unload_seat (manager);
@@ -1340,15 +1336,24 @@ get_x11_display_for_new_session (ActUserManagerNewSess
                          session_type,
                          new_session->id);
                 x11_display = NULL;
-                goto done;
+                //goto done;
         }
 
-        res = sd_session_get_display (new_session->id,
-                                      &x11_display);
-        if (res < 0) {
-                g_debug ("ActUserManager: Failed to get the x11 display of session '%s': %s",
-                         new_session->id,
-                         strerror (-res));
+        ActUserManager *manager;
+        g_autoptr(GError) error = NULL;
+
+        manager = ACT_USER_MANAGER (new_session->manager);
+        ActUserManagerPrivate *priv = act_user_manager_get_instance_private (manager);
+        if (!lib_consolekit_session_get_display (priv->ck,
+                                                 new_session->id,
+                                                 &x11_display, &error)) {
+                if (error != NULL) {
+                        g_debug ("ActUserManager: Failed to get the x11 display of session '%s': %s",
+                                 new_session->id, error->message);
+                } else {
+                        g_debug ("ActUserManager: Failed to get the x11 display of session '%s'",
+                                 new_session->id);
+                }
                 g_debug ("ActUserManager: Treating X11 display as blank");
                 x11_display = strdup ("");
         } else {
@@ -1356,7 +1361,7 @@ get_x11_display_for_new_session (ActUserManagerNewSess
                          new_session->id, x11_display);
         }
 
-done:
+//done:
         new_session->x11_display = g_strdup (x11_display);
         new_session->state++;
 
@@ -1627,10 +1632,6 @@ static gboolean
 on_session_monitor_event (GPollableInputStream *stream,
                           ActUserManager       *manager)
 {
-        ActUserManagerPrivate *priv = act_user_manager_get_instance_private (manager);
-
-        sd_login_monitor_flush (priv->seat.session_monitor);
-        reload_systemd_sessions (manager);
         return TRUE;
 }
 
@@ -1638,31 +1639,13 @@ static void
 _monitor_for_systemd_session_changes (ActUserManager *manager)
 {
         ActUserManagerPrivate *priv = act_user_manager_get_instance_private (manager);
-        int res;
-        int fd;
-        GSource *source;
+        priv->ck = lib_consolekit_new ();
 
-        res = sd_login_monitor_new ("session", &priv->seat.session_monitor);
-
-        if (res < 0) {
-                g_warning ("Failed to monitor logind session changes: %s",
-                           strerror (-res));
+        if (priv->ck == NULL) {
+                g_warning ("Failed to connect to the ConsoleKit daemon");
                 unload_seat (manager);
                 return;
         }
-
-        fd = sd_login_monitor_get_fd (priv->seat.session_monitor);
-
-        priv->seat.session_monitor_stream = g_unix_input_stream_new (fd, FALSE);
-        source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (priv->seat.session_monitor_stream),
-                                                        NULL);
-        g_source_set_callback (source,
-                               (GSourceFunc)
-                               on_session_monitor_event,
-                               manager,
-                               NULL);
-        priv->seat.session_monitor_source_id = g_source_attach (source, NULL);
-        g_source_unref (source);
 }
 
 static void
@@ -2046,7 +2029,7 @@ maybe_set_is_loaded (ActUserManager *manager)
         /* Don't set is_loaded yet unless the seat is already loaded enough
          * or failed to load.
          */
-        if (priv->seat.state > ACT_USER_MANAGER_SEAT_STATE_GET_ID) {
+        if (priv->seat.state >= ACT_USER_MANAGER_SEAT_STATE_GET_ID) {
                 g_debug ("ActUserManager: Seat loaded, so now setting loaded property");
         } else if (priv->seat.state == ACT_USER_MANAGER_SEAT_STATE_UNLOADED) {
                 g_debug ("ActUserManager: Seat wouldn't load, so giving up on it and setting loaded property");
@@ -2528,16 +2511,8 @@ act_user_manager_finalize (GObject *object)
                 g_source_remove (priv->seat.load_idle_id);
         }
 
-        if (priv->seat.session_monitor != NULL) {
-                sd_login_monitor_unref (priv->seat.session_monitor);
-        }
-
-        if (priv->seat.session_monitor_stream != NULL) {
-                g_object_unref (priv->seat.session_monitor_stream);
-        }
-
-        if (priv->seat.session_monitor_source_id != 0) {
-                g_source_remove (priv->seat.session_monitor_source_id);
+        if (priv->ck != NULL) {
+                g_object_unref (priv->ck);
         }
 
         if (priv->accounts_proxy != NULL) {
